package com.bocek.chakmapoint.view.toolbar;

import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;

import com.bocek.chakmapoint.controller.SlideEditController;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TextToolbarView extends JPanel {
	private static final long serialVersionUID = 2238898665589500455L;
	private static TextToolbarView instance = null;
	
	public static TextToolbarView getInstance() {
		
		if (instance == null) {
			instance = new TextToolbarView();
		}
		return instance;
	}

	/**
	 * Create the panel.
	 */
	private TextToolbarView() {
		
		JLabel lblToolText = new JLabel("Tool: Text");
		add(lblToolText);
		
		JButton btnBold = new JButton("Bold");
		btnBold.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SlideEditController.getInstance().toggleBold();
			}
		});
		add(btnBold);
		
		JButton btnItalic = new JButton("Italic");
		btnItalic.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SlideEditController.getInstance().toggleItalic();
			}
		});
		add(btnItalic);
		
		JButton btnSelectColor = new JButton("Select Color");
		btnSelectColor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Color color = JColorChooser.showDialog(null,
						"Choose Line Color", SlideEditController.getInstance().getSelectedItemColor());

				if (color != null)
					SlideEditController.getInstance().setColor(color);
			}
		});
		add(btnSelectColor);
	}

}
